package org.example.helloworld.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.example.helloworld.entity.History;
import org.example.helloworld.entity.Notice;
import org.example.helloworld.mapper.HistoryMapper;
import org.example.helloworld.service.HistoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;


@Service
public class HistoryServiceImpl extends ServiceImpl<HistoryMapper, History> implements HistoryService {

    @Autowired
    private HistoryMapper historyMapper;

    @Override
    public IPage<History> getHistoryList(Page<History> page, String search, Long userId) {
        QueryWrapper<History> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("user_id", userId);
        if (search != null && !search.isEmpty()) {
            queryWrapper.lambda().like(History::getpreId, search);
        }
        return historyMapper.selectPage(page, queryWrapper);
    }

    public boolean removeByIds(List<Long> ids) {
        return historyMapper.deleteBatchIds(ids) > 0;
    }

}
